import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'hor_single_choice_list_view.dart';

class HorSingleChoiceListState extends State<HorSingleChoiceList> {

  HorSingleChoiceListState() {

  }

  @override
  Widget build(BuildContext context) {
    ////懒加载模式构建
    return ListView.builder(
      scrollDirection: Axis.horizontal,

      ///子Item的构建器
      itemBuilder: (BuildContext context, int index) {
        ///每个子Item的布局
        ///在这里是封装到了独立的 StatefulWidget
        return Material(
          child: Container(
            padding:const EdgeInsets.fromLTRB(4, 10, 4, 10),
            child:
            ElevatedButton(
              style: ElevatedButton.styleFrom(
                  shape: RoundedRectangleBorder(
                      side: const BorderSide(
                        color: Colors.black54,
                        width: 1.0,
                      ),
                    borderRadius: BorderRadius.circular(6.0),
                  ),
                  padding: const EdgeInsets.fromLTRB(10, 4, 10, 4),
                  foregroundColor: Colors.black,
                  backgroundColor: widget.datas[index].selected? widget.selelctColor:Colors.white,
                  textStyle:const TextStyle(fontSize: 16)),
              onPressed: () =>{
                  if(null != widget.onSelectChanged){
                    widget.onSelectChanged!(index),
                  }},
              child:  Text(widget.datas[index].getTag()), //选中的颜色字体颜色
            )
            /*ChoiceChip(
                label: Text(widget.datas[index].getTag()),
                selectedColor:Colors.orange,
                selected: widget.datas[index].selected,
                padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
                onSelected: (bool selected) {
                  if(null != widget.onSelectChanged){
                    widget.onSelectChanged!(index);
                  }
                }
            )*/ ,
          ),
        );
      },
      ///ListView子Item的个数
      itemCount: widget.datas.length,
    );
  }

}
